/*
	PlAr is Platform Arena: a 2D multiplayer shooting game
	Copyright (c) 2010, Antonio Ragagnin <spocchio@gmail.com>
    All rights reserved.

    This file is licensed under the New BSD License.
*/

package plar.core;


import java.util.List;
import plar.core.Common;
/**
 * Provides functionality to a Player, check if player is died or set it when is
 * created
 *
 * @author Antonio Ragagnin
 *
 */
public class ActionCharacterStatus extends Action {

	/**
	* true if the player will be respawned after a death (energy became negative)
	*/
    public boolean respawn=true;

    public void run() {

        ElementPlayer p = (ElementPlayer) me;
        if (p.energy <= 0) {

            me.level.delElement(p);
            p.killed++;
            if(p.lastTouch!=null)p.lastTouch.kills++;
            if(respawn)
                me.level.reSpawn(p);

            Common.info(3, "ActionCharacterStatus::run() " + p + " died");
        }

    }

	/**
	* this function is called by the Game with the neccessary informations to initialize the new class {@link Player}.
	* I decided to pass the parameters into a object becouse this is a standard function implemented by {@link Action},
	* and it can be called without casting the action this class..
	*
	* @param o a {@link PlayerSpawnInfo} object with the essential information to inizialize a player.
	*/
    public Object force(Object o) {
		Common.PlayerSpawnInfo asi = (Common.PlayerSpawnInfo)o;
		

        ElementPlayer p = (ElementPlayer) me;
        p.energy = asi.energy;
		p.gl=asi.guns;

        Common.info(3, "ActionCharacterStatus::run() creates " + me+ " E: "+p.energy);

		//start the personalized initialization of the character.
        p.initComponents();
        return p;

    }
}
